home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Resource for Source: C/C++
/
Resource for Source - C-C++.iso
/
codelib1
/
v_01_05
/
1n05054b
< prev
next >
Wrap
Text File
|
1995-11-01
|
1KB
|
63 lines
/* Listing4.c */
#include <graphics.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void SetPaletteRegister (int nRegister, int nPaletteNumber);
void SetControllerMode (int nMode);
void SetPalettePage (int nPage);
void SetColorRegister (int nRegister, int nRed, int nGreen, int nBlue);
void main()
{
int i;
int nWidth, nHeight;
int nLeft, nTop, nRight, nBottom;
int nDriver, nMode, nError;
/* initialize Borlands graphic driver */
detectgraph (&nDriver, &nMode);
if (nDriver != VGA)
{
printf ("This program requires VGA adapter!\n");
exit (1);
}
initgraph (&nDriver, &nMode, "");
nError = graphresult();
if (nError < 0)
{
printf ("initgraph error %s.\n", grapherrormsg (nError));
exit (1);
}
/* Draw 16 blocks on the screen filled with 16 colors */
nWidth = 640 / 8;
nHeight = 480 / 2;
for (i = 0; i < 16; i++)
{
nLeft = (i % 8) * nWidth;
nRight = nLeft + nWidth;
nTop = (i / 8) * nHeight;
nBottom = nTop + nHeight;
setfillstyle (SOLID_FILL, i);
bar (nLeft, nTop, nRight, nBottom);
}
getch();
/* Set the palette registers to point to color registers 0 - 15 */
SetPalettePage (0);
for (i = 0; i < 16; i++) SetPaletteRegister (i, i);
getch();
/* Change the color registers to be shades of red */
for (i = 0; i < 16; i++) SetColorRegister (i, i * 4, 0, 0);
getch();
clrscr();
closegraph();
}